package com.jade.store.wechat.biz.protocol.auth;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * 推送authPush协议
 * User: jinya
 * Date: 2016/12/13
 * Time: 13:18
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
public class AuthPush {
    // 第三方平台appid
    private String AppId;
    // 时间戳
    private String CreateTime;

    // authPush
    private String InfoType;

    // Ticket内容
    private String ComponentVerifyTicket;
    private String AuthorizerAppid;
    private String AuthorizationCode;
    private String AuthorizationCodeExpiredTime;
    // 获取其对应的xml数据串
    public String getXML() {
        XStream xStream = new XStream(new DomDriver());
        xStream.alias("xml", this.getClass());
        // 设置成员的别名
        xStream.aliasField("AppId", this.getClass(), "AppId");
        xStream.aliasField("CreateTime", this.getClass(), "CreateTime");
        xStream.aliasField("InfoType", this.getClass(), "InfoType");
        xStream.aliasField("ComponentVerifyTicket", this.getClass(), "ComponentVerifyTicket");
        return xStream.toXML(this);
    }

    /**
     * 根据xml数据获取Component_verify_ticket对象
     *
     * @param xml
     * @return
     */
    public AuthPush getComponent_verify_ticket(String xml) {
        XStream xStream = new XStream(new DomDriver());
        xStream.alias("xml", this.getClass());
        // 设置成员的别名
        xStream.aliasField("AppId", this.getClass(), "AppId");
        xStream.aliasField("CreateTime", this.getClass(), "CreateTime");
        xStream.aliasField("InfoType", this.getClass(), "InfoType");
       // xStream.aliasField("ComponentVerifyTicket", this.getClass(), "ComponentVerifyTicket");
        AuthPush temp = (AuthPush) xStream.fromXML(xml);

        XStream newStream = new XStream(new DomDriver());
        newStream.alias("xml", this.getClass());
        // 设置成员的别名
        newStream.aliasField("AppId", this.getClass(), "AppId");
        newStream.aliasField("CreateTime", this.getClass(), "CreateTime");
        newStream.aliasField("InfoType", this.getClass(), "InfoType");
        if(temp.getInfoType().equals("component_verify_ticket")){//频率推送
            newStream.aliasField("ComponentVerifyTicket", this.getClass(), "ComponentVerifyTicket");
        }else if(temp.getInfoType().equals("updateauthorized")){//（授权更新通知）
            newStream.aliasField("AuthorizerAppid", this.getClass(), "AuthorizerAppid");
            newStream.aliasField("AuthorizationCode", this.getClass(), "AuthorizationCode");
            newStream.aliasField("AuthorizationCodeExpiredTime", this.getClass(), "AuthorizationCodeExpiredTime");
        }else if(temp.getInfoType().equals("authorized")){//（授权成功通知）
            newStream.aliasField("AuthorizerAppid", this.getClass(), "AuthorizerAppid");
            newStream.aliasField("AuthorizationCode", this.getClass(), "AuthorizationCode");
            newStream.aliasField("AuthorizationCodeExpiredTime", this.getClass(), "AuthorizationCodeExpiredTime");
        }else if(temp.getInfoType().equals("unauthorized")){//（取消授权通知）
            newStream.aliasField("AuthorizerAppid", this.getClass(), "AuthorizerAppid");
        }
        AuthPush authPush=(AuthPush) newStream.fromXML(xml);
        return authPush;
    }

    public String getAppId() {
        return AppId;
    }

    public void setAppId(String appId) {
        AppId = appId;
    }

    public String getCreateTime() {
        return CreateTime;
    }

    public void setCreateTime(String createTime) {
        CreateTime = createTime;
    }

    public String getInfoType() {
        return InfoType;
    }

    public void setInfoType(String infoType) {
        InfoType = infoType;
    }

    public String getComponentVerifyTicket() {
        return ComponentVerifyTicket;
    }

    public void setComponentVerifyTicket(String componentVerifyTicket) {
        ComponentVerifyTicket = componentVerifyTicket;
    }

    public String getAuthorizerAppid() {
        return AuthorizerAppid;
    }

    public void setAuthorizerAppid(String authorizerAppid) {
        AuthorizerAppid = authorizerAppid;
    }

    public String getAuthorizationCode() {
        return AuthorizationCode;
    }

    public void setAuthorizationCode(String authorizationCode) {
        AuthorizationCode = authorizationCode;
    }

    public String getAuthorizationCodeExpiredTime() {
        return AuthorizationCodeExpiredTime;
    }

    public void setAuthorizationCodeExpiredTime(String authorizationCodeExpiredTime) {
        AuthorizationCodeExpiredTime = authorizationCodeExpiredTime;
    }
}
